<?php
/*
 * ----------------------------------------------------------------------------
 * 'GuMax' style sheet for CSS2-capable browsers.
 *       Loosely based on the monobook style
 *
 * @Version 5.0.0
 * @Author Paul Y. Gu, <gu.paul@gmail.com>
 * @Copyright paulgu.com 2007 - http://www.paulgu.com/
 * @License: GPL (http://www.gnu.org/copyleft/gpl.html)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * http://www.gnu.org/copyleft/gpl.html
 * ----------------------------------------------------------------------------
 */

if( !defined( 'MEDIAWIKI' ) )
    die( -1 );

/**
 * Inherit main code from SkinTemplate, set the CSS and template filter.
 * @todo document
 * @addtogroup Skins
 */
class SkinGuMax extends SkinTemplate {
	/** Using GuMax */
	var $skinname = 'gumax', $stylename = 'gumax',
		$template = 'GuMaxTemplate', $useHeadElement = true;

	function setupSkinUserCss( OutputPage $out ) {
		global $wgHandheldStyle;

		parent::setupSkinUserCss( $out );

		// Append to the default screen common & print styles...
		$out->addStyle( 'gumax/gumax_main.css', 'screen' );
		if( $wgHandheldStyle ) {
			// Currently in testing... try 'chick/main.css'
			$out->addStyle( $wgHandheldStyle, 'handheld' );
		}

		$out->addStyle( 'gumax/IE50Fixes.css', 'screen', 'lt IE 5.5000' );
		$out->addStyle( 'gumax/IE55Fixes.css', 'screen', 'IE 5.5000' );
		$out->addStyle( 'gumax/IE60Fixes.css', 'screen', 'IE 6' );
		$out->addStyle( 'gumax/IE70Fixes.css', 'screen', 'IE 7' );

		$out->addStyle( 'gumax/gumax_rtl.css', 'screen', '', 'rtl' );
		$out->addStyle( 'gumax/gumax_print.css', 'print' );
	}
}

/**
 * @todo document
 * @addtogroup Skins
 */
class GuMaxTemplate extends QuickTemplate {
	var $skin;
	/**
	 * Template filter callback for GuMax skin.
	 * Takes an associative array of data set from a SkinTemplate-based
	 * class, and a wrapper for MediaWiki's localization database, and
	 * outputs a formatted page.
	 *
	 * @access private
	 */
    function execute() {
		global $wgRequest;
		$this->skin = $skin = $this->data['skin'];
		$action = $wgRequest->getText( 'action' );


		// Suppress warnings to prevent notices about missing indexes in $this->data
		wfSuppressWarnings();

		$this->html( 'headelement' );

?><div id="gumax-wrapper">

<table border="0" id="gumax-page-table"><tr><td id="gumax-page-table-left"><img src="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/blank.gif" alt="" /></td><td width="100%" valign="top" style="padding: 0; margin: 0" id="gumax-page-table-content">


<!-- ===== gumax-page ===== -->
<div class="gumax-page">

	<!-- ///// gumax-header ///// -->
	<div id="gumax-header">
		<a name="top" id="contentTop"></a>

	<?php $this->loginBox(); ?>
	<?php $this->logoBox(); ?>
	<?php $this->searchBox(); ?>

	</div>
	<!-- ///// end of gumax-header ///// -->
	<div class="visualClear"></div>


	<?php $this->topNavigationBox(); ?>
	<div class="gumax-p-navigation-spacer"></div>
	<div class="visualClear"></div>

	<!-- ///// gumax-body ///// -->
	<div id="gumax-body">

		<?php $this->articlePictureBox(); ?>

		<table border="0" id="gumax-content-table" width="100%"><tr><td id="gumax-content-table-left" valign="top" style="padding: 0; margin: 0">
			<?php $this->sidebarNavigationBox(); ?>
			<?php $this->languageBox(); ?>
		</td><td id="gumax-content-table-right" width="100%" valign="top" style="padding: 0; margin: 0" >
			<?php $this->contentActionBox(); ?>
			<?php $this->contentBox(); ?>
		</td></tr></table>

		<!-- ///// gumax-footer ///// -->
		<div id="gumax-footer">
			<?php $this->toolBox(); ?>
			<div class="gumax-footer-spacer"></div>
			<?php $this->footerBox(); ?>
		</div>
		<!-- ///// end of gumax-footer ///// -->

	</div>
	<!-- ///// end of gumax-body ///// -->

</div>
<!-- ===== end of gumax-page ===== -->

	</td><td id="gumax-page-table-right"><img src="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/blank.gif" alt="" /></td></tr></table>
	<!--[if lt IE 7]> <script type="text/javascript" src="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/js/ieunitpngfix-tag.js"></script> <![endif]-->
	<!--[if lt IE 7]> <script type="text/javascript">pngfix('td');</script> <![endif]-->

</div>
<!-- ##### end of gumax-wrapper ##### -->


<?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
<?php $this->html('reporttime') ?>
<?php if ( $this->data['debug'] ): ?>
<!-- Debug output:
<?php $this->text( 'debug' ); ?>

-->
<?php endif; ?>
</body></html>





<?php
	wfRestoreWarnings();
	} // end of execute() method


	/*************************************************************************************************/
	// GuMax Functions
	/*************************************************************************************************/

	function loginBox() {
?>
	<!-- Login -->
	<div id="gumax-p-login">
		<ul>
<?php		$lastkey = end(array_keys($this->data['personal_urls'])) ?>
<?php		foreach($this->data['personal_urls'] as $key => $item) { ?>
				<li id="pt-<?php echo Sanitizer::escapeId($key) ?>"<?php
					if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
					echo htmlspecialchars($item['href']) ?>"   <?php
					if(!empty($item['class'])) { ?> class="<?php
					echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
					echo htmlspecialchars($item['text']) ?></a></li>
<?php				if($key != $lastkey) echo "<li>&#47;</li>" ?>
<?php		} ?>
		</ul>
	</div>
	<!-- end of Login -->
<?php
	}

	/*************************************************************************************************/
	function logoBox() {
?>
	<!-- gumax-p-logo -->
	<div id="gumax-p-logo">
		<div id="p-logo">
			<a style="background-image: url(<?php $this->text('logopath') ?>);" <?php
				?>href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href'])?>" <?php
				?>title="<?php $this->msg('mainpage') ?>"></a>
		</div>
	</div>
	<script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha(); </script>
	<!-- end of gumax-p-logo -->
<?php
	}

	/*************************************************************************************************/
	function searchBox() {
?>
	<!-- Search -->
	<div id="gumax-p-search" class="gumax-portlet">
		<h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
		<div id="gumax-searchBody" class="gumax-pBody">
			<form action="<?php $this->text('searchaction') ?>" id="searchform"><div>
				<input id="searchInput" name="search" type="text" <?php
					if($this->haveMsg('accesskey-search')) {
						?>accesskey="<?php $this->msg('accesskey-search') ?>"<?php }
					if( isset( $this->data['search'] ) ) {
						?> value="<?php $this->text('search') ?>"<?php } ?> />
				<input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg('searcharticle') ?>"    />
				<input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg('searchbutton') ?>"    />
			</div></form>
		</div>
	</div>
	<!-- end of Search -->
<?php
	}

	/*************************************************************************************************/
	function topNavigationBox() {
?>
	<!-- Navigation Menu -->
	<div id="gumax-p-navigation">
<?php	$counter = 0; ?>
<?php	foreach ($this->data['sidebar'] as $bar => $cont) { ?>
<?php		$counter++; ?>
<?php		if ( $counter == 1 ) { ?>
				<div class="gumax-portlet gumax-p-navigation">
					<h5><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo $bar; else echo $out; ?></h5>
	<?php			if ( is_array( $cont ) ) { ?>

							<ul>
	<?php						foreach($cont as $key => $val) { ?>
									<li id="<?php echo Sanitizer::escapeId($val['id']) ?>"<?php
										if ( $val['active'] ) { ?> class="active" <?php }
									?>><a href="<?php echo htmlspecialchars($val['href']) ?>"   ><?php echo htmlspecialchars($val['text']) ?></a></li>
	<?php						} ?>
							</ul>

	<?php			} else {
						# allow raw HTML block to be defined by extensions
						print $cont;
					} ?>
				</div>
<?php		} ?>
<?php	} ?>
	</div>
	<!-- end of Navigation Menu -->
<?php
	}

	/*************************************************************************************************/
	function sidebarNavigationBox() {
?>
	<!-- Navigation Menu -->
	<div id="gumax-p-navigation-sidebar">
<?php	$counter = 0; ?>
<?php	foreach ($this->data['sidebar'] as $bar => $cont) { ?>
<?php		$counter++; ?>
<?php		if ( $counter > 1 ) { ?>
				<div class="generated-sidebar gumax-portlet-sidebar">
					<h5><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo $bar; else echo $out; ?></h5>
	<?php			if ( is_array( $cont ) ) { ?>

							<ul>
	<?php						foreach($cont as $key => $val) { ?>
									<li id="<?php echo Sanitizer::escapeId($val['id']) ?>"<?php
										if ( $val['active'] ) { ?> class="active" <?php }
									?>><a href="<?php echo htmlspecialchars($val['href']) ?>"   ><?php echo htmlspecialchars($val['text']) ?></a></li>
	<?php						} ?>
							</ul>

	<?php			} else {
						# allow raw HTML block to be defined by extensions
						print $cont;
					} ?>
				</div>
<?php		} ?>
<?php	} ?>
	</div>
	<!-- end of Navigation Menu -->
<?php
	}

	/*************************************************************************************************/
	function languageBox() {
		if( $this->data['language_urls'] ) {
?>
	<div id="p-lang" class="portlet">
		<h5><?php $this->msg('otherlanguages') ?></h5>
		<div class="pBody">
			<ul>
<?php		foreach($this->data['language_urls'] as $langlink) { ?>
				<li class="<?php echo htmlspecialchars($langlink['class'])?>"><?php
				?><a href="<?php echo htmlspecialchars($langlink['href']) ?>"><?php echo $langlink['text'] ?></a></li>
<?php		} ?>
			</ul>
		</div>
	</div>
<?php
		}
	}

	/*************************************************************************************************/
	function contentActionBox() {
		global $wgUser;
		$skin = $wgUser->getSkin();
?>
	<!-- gumax-content-actions -->
	<?php //if($this->data['loggedin']==1) { ?>
	<div id="gumax-content-actions">
		<ul><?php
			foreach($this->data['content_actions'] as $key => $tab) {
				echo '
			 <li id="' . Sanitizer::escapeId( "ca-$key" ) . '"';
				if( $tab['class'] ) {
					echo ' class="'.htmlspecialchars($tab['class']).'"';
				}
				echo '><a href="'.htmlspecialchars($tab['href']).'"';
				# We don't want to give the watch tab an accesskey if the
				# page is being edited, because that conflicts with the
				# accesskey on the watch checkbox.  We also don't want to
				# give the edit tab an accesskey, because that's fairly su-
				# perfluous and conflicts with an accesskey (Ctrl-E) often
				# used for editing in Safari.

				echo '>'.htmlspecialchars($tab['text']).'</a></li>';
			} ?>
		</ul>
	</div>
	<?php //} ?>
	<!-- end of gumax-content-actions -->
<?php
	}

	/*************************************************************************************************/
	function articlePictureBox() {
?>
<?php
		$pageClasses = preg_split("/[\s]+/", $this->data['pageclass']); /* echo $this->data['pageclass']; */
		foreach($pageClasses as $item){ if(strpos($item, "page-") !== false){ $page_class = $item; /* echo $page_class; */ } }

		$file_ext_collection = array('.jpg', '.gif', '.png');
		$found = false;
		foreach ($file_ext_collection as $file_ext)
		{
			$gumax_article_picture_file = $this->data['stylepath'] . '/' . $this->data['stylename'] . '/images/pages/' . $page_class . $file_ext;
			if (file_exists( $_SERVER['DOCUMENT_ROOT'] . '/' .$gumax_article_picture_file)) {
				$found = true;
				break;
			}
		}
		// default article picture
		if(!$found) {
			$gumax_article_picture_file = $this->data['stylepath'] . '/' . $this->data['stylename'] . '/images/pages/' . 'page-Default.gif';
			if (file_exists( $_SERVER['DOCUMENT_ROOT'] . '/' .$gumax_article_picture_file)) {
				$found = true;
			}
		}
		if($found) { ?>
		<!-- gumax-article-picture -->
			<div id="gumax-article-picture">
				<a style="background-image: url(<?php echo $gumax_article_picture_file ?>);" <?php
					?>href="<?php echo htmlspecialchars( $GLOBALS['wgTitle']->getLocalURL() )?>" <?php
					?>title="<?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?>"></a>
			</div>
			<div class="gumax-article-picture-spacer"></div>
		<!-- end of gumax-article-picture -->
<?php
		}
	}

	/*************************************************************************************************/
	function contentBox() {
?>
	<!-- gumax-content-body -->
		<div id="gumax-column-content">
	<div id="content">
		<a name="top" id="top"></a>
		<?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
		<h1 id="firstHeading" class="firstHeading gumax-firstHeading" ><?php $this->html('title') ?></h1>
		<div id="bodyContent" class="gumax-bodyContent">
			<h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
			<div id="contentSub"><?php $this->html('subtitle') ?></div>
			<?php if($this->data['undelete']) { ?><div id="contentSub2"><?php     $this->html('undelete') ?></div><?php } ?>
			<?php if($this->data['newtalk'] ) { ?><div class="usermessage"><?php $this->html('newtalk')  ?></div><?php } ?>
			<?php if($this->data['showjumplinks']) { ?><div id="jump-to-nav"><?php $this->msg('jumpto') ?> <a href="#column-one"><?php $this->msg('jumptonavigation') ?></a>, <a href="#searchInput"><?php $this->msg('jumptosearch') ?></a></div><?php } ?>
			<!-- start content -->
			<?php $this->html('bodytext') ?>
			<?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
			<!-- end content -->
			<?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
			<div class="visualClear"></div>
		</div>
	</div>
		</div>
	<!-- end of gumax-content-body -->
<?php
	}

	/*************************************************************************************************/
	function toolbox() {
?>
	<!-- personal tools  -->
	<div id="gumax-personal-tools">
		<h5><?php $this->msg('toolbox') ?></h5>
		<ul>
<?php
		if($this->data['notspecialpage']) { ?>
				<li id="t-whatlinkshere"><a href="<?php
				echo htmlspecialchars($this->data['nav_urls']['whatlinkshere']['href'])
				?>"   ><?php $this->msg('whatlinkshere') ?></a></li>
				<li>&#47;</li>
<?php
			if( $this->data['nav_urls']['recentchangeslinked'] ) { ?>
				<li id="t-recentchangeslinked"><a href="<?php
				echo htmlspecialchars($this->data['nav_urls']['recentchangeslinked']['href'])
				?>"   ><?php $this->msg('recentchangeslinked') ?></a></li>
				<li>&#47;</li>
<?php 		}
		}
		if(isset($this->data['nav_urls']['trackbacklink'])) { ?>
			<li id="t-trackbacklink"><a href="<?php
				echo htmlspecialchars($this->data['nav_urls']['trackbacklink']['href'])
				?>"   ><?php $this->msg('trackbacklink') ?></a></li>
				<li>&#47;</li>
<?php 	}
		if($this->data['feeds']) { ?>
			<li id="feedlinks"><?php foreach($this->data['feeds'] as $key => $feed) {
					?><span id="feed-<?php echo Sanitizer::escapeId($key) ?>"><a href="<?php
					echo htmlspecialchars($feed['href']) ?>"   ><?php echo htmlspecialchars($feed['text'])?></a>&nbsp;</span>
					<?php } ?></li>
					<li>&#47;</li><?php
		}

		foreach( array('contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages') as $special ) {
			if($this->data['nav_urls'][$special]) {
				?><li id="t-<?php echo $special ?>"><a href="<?php echo htmlspecialchars($this->data['nav_urls'][$special]['href'])
				?>"   ><?php $this->msg($special) ?></a></li>
<?php			if($special != 'specialpages') echo "<li>&#47;</li>"; ?>
<?php		}
		}

		if(!empty($this->data['nav_urls']['print']['href'])) { ?>
				<li>&#47;</li>
				<li id="t-print"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['print']['href'])
				?>"   ><?php $this->msg('printableversion') ?></a></li><?php
		}

		if(!empty($this->data['nav_urls']['permalink']['href'])) { ?>
				<li>&#47;</li>
				<li id="t-permalink"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['permalink']['href'])
				?>"   ><?php $this->msg('permalink') ?></a></li><?php
		} elseif ($this->data['nav_urls']['permalink']['href'] === '') { ?>
				<li>&#47;</li>
				<li id="t-ispermalink"<?php echo $this->skin->tooltip('t-ispermalink') ?>><?php $this->msg('permalink') ?></li><?php
		}

		wfRunHooks( 'GuMaxTemplateToolboxEnd', array( &$this ) );
		wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
?>
		</ul>
	</div>
	<!-- end of personal tools  -->
<?php
	}

	/*************************************************************************************************/

	function gumaxLastModified() {
		global $wgLang, $wgArticle;
		if ( !$wgArticle ) return '';

		if( $this->mRevisionId ) {
			$timestamp = Revision::getTimestampFromId( $this->mRevisionId, $wgArticle->getId() );
		} else {
			$timestamp = $wgArticle->getTimestamp();
		}
		if ( $timestamp ) {
			$d = $wgLang->date( $timestamp, true );
			$t = $wgLang->time( $timestamp, true );
			//$s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
			$s = 'modified on ' . $d . ' at ' . $t;
		} else {
			$s = '';
		}
		//if ( wfGetLB()->getLaggedSlaveMode() ) {
		//	$s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
		//}
		return $s;
	}

	/*************************************************************************************************/

	function gumaxViewcount() {
		global $wgDisableCounters;
		if ( $wgDisableCounters ) return '';

		global $wgLang, $wgArticle;
		if ( is_object( $wgArticle ) ) {
			$viewcount = $wgLang->formatNum( $wgArticle->getCount() );
			if ( $viewcount ) {
				//$viewcount = wfMsg( "viewcount", $viewcount );
				$viewcount = $viewcount . " views";
			} else {
				$viewcount = '';
			}
		} else {
			$viewcount = '';
		}
		return $viewcount;
	}

	/*************************************************************************************************/

	function gumaxMessage() {
?>
		<div id="gumax-f-message">
			<?php if($this->data['lastmod']) { ?><span id="f-lastmod"><?php $this->html('lastmod') ?></span>
			<?php } ?><?php if($this->data['viewcount']) { ?><span id="f-viewcount"><?php  $this->html('viewcount') ?> </span>
			<?php } ?>
		</div>
<?php
	}

	/*************************************************************************************************/
	function footerBox() {
?>
	<!-- gumax-f-list -->
	<div id="gumax-f-list">
		<ul>
			<?php
					$footerlinks = array(
						'numberofwatchingusers', 'credits',
						'privacy', 'about', 'disclaimer', 'tagline',
					);
					foreach( $footerlinks as $aLink ) {
						if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
			?>				<li id="<?php echo$aLink?>"><?php $this->html($aLink) ?></li>
							<?php		echo "<li>/</li>"	?>
			<?php 		}
					}
			?>
			<li><a href="http://www.solidaritychain.dev/index.php/SolidariteChain:Contact" target="_blank">Contacts</a></li>
			
		</ul>
	</div>
	<!-- end of gumax-f-list -->
<?php
	}

	/*************************************************************************************************/


} // end of class

